package com.xhwl.logistics.converter.mapstruct;

import com.xhwl.common.dto.cent.vehicle.feign.VehicleFindCarQuery;
import com.xhwl.logistics.bo.VehicleFindCarBO;
import com.xhwl.logistics.bo.input.QueryVehicleFindCarBO;
import com.xhwl.logistics.dto.http.CarLocationKeTopDTO;
import com.xhwl.logistics.dto.http.CarRouteKeTopDTO;
import com.xhwl.logistics.dto.http.query.QueryCarLocationKeTopDTO;
import com.xhwl.logistics.dto.http.query.QueryCarRouteKeTopDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueMappingStrategy;
import org.springframework.util.StringUtils;

@Mapper(componentModel = "spring", nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface VehicleFindCarConverter {

    @Mapping(source = "plateNumber", target = "plateNo")
    QueryCarLocationKeTopDTO queryVehicleFindCarBO2QueryCarLocationKeTopDTO(QueryVehicleFindCarBO queryVehicleFindCarBO);

    @Mapping(source = "queryVehicleFindCarBO.carportNumber", target = "beginSpaceNo")
    @Mapping(source = "carLocationKeTopDTO.spaceNo", target = "endSpaceNo")
    @Mapping(target = "parkId", ignore = true)
    QueryCarRouteKeTopDTO toQueryCarRouteKeTopDTO(QueryVehicleFindCarBO queryVehicleFindCarBO, CarLocationKeTopDTO carLocationKeTopDTO);

    @Mapping(source = "spaceNo", target = "carportNumber")
    @Mapping(source = "carImage", target = "parkingImageUrl")
    @Mapping(target = "routeUrl", ignore = true)
    VehicleFindCarBO carLocationKeTopDTO2VehicleFindCarBO(CarLocationKeTopDTO carLocationKeTopDTO);

    @Mapping(source = "carLocationKeTopDTO.spaceNo", target = "carportNumber")
    @Mapping(source = "carLocationKeTopDTO.carImage", target = "parkingImageUrl")
    @Mapping(source = "carRouteKeTopDTO.routeUrl", target = "routeUrl")
    VehicleFindCarBO toVehicleFindCarBO(CarLocationKeTopDTO carLocationKeTopDTO, CarRouteKeTopDTO carRouteKeTopDTO);


    default QueryVehicleFindCarBO vehicleFindCarQuery2QueryVehicleFindCarBO(VehicleFindCarQuery vehicleFindCarQuery) {
        QueryVehicleFindCarBO queryVehicleFindCarBO = new QueryVehicleFindCarBO();
        queryVehicleFindCarBO.setProjectId(vehicleFindCarQuery.getProjectId());
        queryVehicleFindCarBO.setParkingLotName(vehicleFindCarQuery.getParkingLotName());
        queryVehicleFindCarBO.setCarportNumber(vehicleFindCarQuery.getCarportNumber());

        String afterDelete = StringUtils.deleteAny(vehicleFindCarQuery.getPlateNumber(), "- ");
        queryVehicleFindCarBO.setPlateNumber(afterDelete.substring(1));
        return queryVehicleFindCarBO;
    }

}
